package com.easonji.admin.controller;

import javax.annotation.Resource;

import com.easonji.common.base.controller.BaseController;
import com.easonji.common.base.response.Response;
import com.easonji.common.base.response.enums.ResponseEnum;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easonji.admin.query.LoginLogQuery;
import com.easonji.admin.service.LoginLogService;
import com.easonji.common.constant.Consts;
import com.easonji.core.annotion.BussinessLog;
import com.easonji.core.annotion.Permission;

/**
 * @ClassName: LoginLogController
 * @Description: 登录日志控制器
 * @Author: LiuJun
 * @date: 2018/07/30 16:11:36
 * @Version: 1.0
 * @Copyright: Copyright (c) 2018 - 2019
 */
@Controller
@RequestMapping("/loginLog")
public class LoginLogController extends BaseController {

    /**
     * 页面前缀
     */
    private final static String PREFIX = "system/log/";

    @Resource
    private LoginLogService loginLogService;

    /**
     * 跳转到登录日志首页
     */
    @GetMapping("")
    public String index() {
        return PREFIX + "login_log";
    }

    /**
     * 查询登录日志列表
     */
    @ResponseBody
    @Permission(Consts.ADMIN_ROLE_NAME)
    @PostMapping("/list")
    public Object queryLoginLogList(LoginLogQuery loginLogQuery) {
        Object result = loginLogService.queryLoginLogList(loginLogQuery);
        return result;
    }

    /**
     * 删除登录日志
     */
    @ResponseBody
    @Permission(Consts.ADMIN_ROLE_NAME)
    @BussinessLog("清空登录日志")
    @PostMapping("/remove")
    public Response removeLoginLog() {
        boolean result = loginLogService.removeLoginLog();
        if (!result) {
            return failure(ResponseEnum.DATABASE_ERROR);
        }
        return success(ResponseEnum.REMOVE_SUCCESS);
    }
}
